#!user/bin/env python3
# -- coding: utf-8 --
# @Createtime：2023/8/20
# @Updatetime：20:43
# @Author：Test008
# @File：1-ui元素定位.py
# @Description：
from selenium import webdriver
import time

# 打开谷歌浏览器
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.implicitly_wait(3)

# 打开指定网址
driver.get('https://www.gushiwen.cn/')
# 1》ID定位元素
ele = driver.find_element(By.ID, 'txtKey')
ele.send_keys('杜甫诗集')

# 2》xpath定位元素
ele = driver.find_element(By.XPATH, '//*[@id="search"]/form/input[3]')
ele.click()

# 3》TAG_NAME属性定位
driver.find_element(By.TAG_NAME, '.son1 a').click()

time.sleep(2)
# 4》NAME属性定位
driver.get('https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx')
driver.find_element(By.NAME, 'email').send_keys('1478243841@qq.com')

# 5》 css路径定位
driver.find_element(By.CSS_SELECTOR, '#pwd').send_keys('123456')
driver.find_element(By.ID, 'imgCode')
time.sleep(10)
# 登录
driver.find_element(By.ID, 'denglu').click()
# 点击古籍，对论语点击纠错
driver.find_element(By.CSS_SELECTOR, '.son1 a:nth-child(5)').click()
driver.find_element(By.CSS_SELECTOR, ' .sonspic .jiucuo a:nth-child(1)').click()

# 6> class_name属性定位
driver.find_element(By.CLASS_NAME, 'left').click()

time.sleep(3)
driver.quit()
